

#include "CxDBThread.h"

#include "CxDBExports.h"

CxDBThread::CxDBThread(size_t number,_ConnectFunc func):
	m_number(number),
	m_spin(true),
	m_buffer(32)
{
	sig_connect.connect(boost::bind(func,_1));

	if(!CxDBCreateInstance(number))
	{
		//·¢ÉäÊ§°ÜÐÅºÅ
		sig_connect(false);
	}
	//·¢Éä³É¹¦ÐÅºÅ
	else sig_connect(true);
}

CxDBThread::~CxDBThread()
{
	//ÖÐ¶ÏÏß³Ì
    m_spin=false;
	m_thread.interrupt();
	m_thread.join();
	CxDBUnInstance(m_number);
}

void	CxDBThread::RunFunc()
{
	try
	{
		while(m_spin)
		{
            boost::this_thread::sleep(boost::posix_time::milliseconds(30));
			Mat _tmpmat=m_buffer.Pop();
            //m_dbhandle->PushImage((BYTE*)_tmpmat.data,
            //	_tmpmat.rows*_tmpmat.cols*3);
//            PushImage(m_number,(BYTE*)_tmpmat.data,
//                _tmpmat.rows*_tmpmat.cols*3);
			boost::this_thread::interruption_point();
		}
	}
	catch(boost::thread_interrupted &)
	{
	}
	catch(const		boost::system::system_error &e)
	{
		cout<<e.what()<<endl;
	}
}
